<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\controller\v1;

use app\api\service\Pay as PayService;
use app\api\service\WxNotify as WxNotifyService;
use app\api\validate\PayValidate;
use think\Request;

/**
 * 支付
 * Class Pay
 * @package app\api\controller\v1
 */
class Pay extends BaseController
{
    /**
     * @desc 检查用户权限
     */
    protected $beforeActionList = [
        'checkUserScope' => ['only' => 'getpreorder'], // 方法名必须全部小写，逗号中间不能有空格！！！
    ];

    /**
     * @Desc 微信支付
     * @return array|string
     */
    public function getPreOrder()
    {
        (new PayValidate())->goCheck();
        $order = Request::instance()->post();
        return (new PayService($order))->pay();
    }

    /**
     * @Desc 微信支付通知
     */
    public function receiveNotify()
    {
        echo (new WxNotifyService())->notify();
    }
}